package LuoGu.二分查找.AB数对;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        st.nextToken();
        int n = (int) st.nval;
        st.nextToken();
        int t = (int) st.nval;
        int [] temp = new int [n];
        for(int i=0;i<n;i++){
            st.nextToken();
            temp[i] = (int) st.nval;
        }
        Arrays.sort(temp);
        long ans = 0;
        for(int i=n-1;i>=1;i--){
            int l = 0;
            int r = i-1;
            int m = (r+l)/2;
            int tempp = temp[i]-t;
            while(l<r){
                if(temp[m]>=tempp) r = m;
                else l = m+1;
                m = (r+l)/2;
            }
            if(temp[i]-temp[l] == t){
                int ll = 0;
                int rr = n-1;
                int mm = (ll+rr)/2;
                //注意中间参数，不要与上面的混淆
                while(ll<rr){
                    if(temp[mm]<=tempp) ll = mm+1;
                    else if(temp[mm]>tempp) rr = mm;
                    mm = (ll+rr)/2;
                }
                //System.out.println(ll);
                ans+=(ll-l);
            }
        }
        System.out.print(ans);
    }
}
